package com.gec.obwiki.aspect;

import com.gec.obwiki.utils.SnowFlake;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogAspect {
    @Autowired
    private SnowFlake snowFlake;

    // 定义切点
    @Pointcut("execution(* com.gec.obwiki.controller..*.*(..))")
    public void controllerPointcut() {}

    //配置前置通知
    @Before("controllerPointcut()")
    public void doBefore(JoinPoint joinPoint) throws Throwable {
        // 增加日志流水号
        MDC.put("LOG_ID", String.valueOf(snowFlake.nextId()));
        //其他代码略
    }

}